Skip to content

[UR][L0 v2] Port USM alloc to adapter v2 #18179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from

Conversation

staniewzki
Copy link
Contributor

@staniewzki staniewzki commented Apr 24, 2025

This PR ports USM alloc enqueue API introduced to L0 adapter in #17112 to L0 adapter v2.

@@ -348,19 +348,21 @@ ur_result_t urEnqueueUSMDeviceAllocExp(
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is auto-generated. If you want to modify it you need to change scripts/templates/queue_api.cpp.mako (same is true for the corresponding .hpp file)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I don't think you need to actually modify it. As far as I understand you wanted to add ur_queue_handle_t param so that you can pass it to EnqueuedPool functions (like getBestFit, etc.). However, if I'm not mistaken, the queue is only used as an identifier by the EnqueuedPool implementation. This means that you can just do something like this in queue_immediate_in_order.cpp:

...
getBestFit(size, alignment, reinterpret_cast<ur_queue_handle_t>(this));

If the EnqueuedPool actually needs to have valid queue handle, then I think it would be better to rewrite EnqueuedPool (which you might need to do anyway, as it has some logic for handling events that is legacy-specific).


auto device = (type == UR_USM_TYPE_HOST) ? nullptr : hDevice;

std::vector<ur_event_handle_t> extendedWaitList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don;t need to create a temporary vector here. commandListManger has getWaitListView function that you should use here (it also accepts an optional extra wait event). You just call: getWaitListView(commandListLocked, phEventWaitList, numEventsInWaitList, originAllocEvent);

return Ret;
}
} else {
*ppMem = std::get<0>(*asyncAlloc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::tie(*ppMem, originAllocEvent) = *asyncAlloc;

const ur_exp_async_usm_alloc_properties_t *pProperties,
uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
void **ppMem, ur_event_handle_t *phEvent) {
return enqueueUSMAllocHelper(hQueue, pPool, size, pProperties,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TRACK_SCOPE_LATENCY("ur_queue_immediate_in_order_t::enqueueUSMHostAllocExp"); at the beginning of this function (and other function you implement in this patch).

@staniewzki staniewzki force-pushed the async-l0-adapter-v2 branch 2 times, most recently from 8fc9615 to 4ac080d Compare April 30, 2025 09:43

umf_memory_pool_handle_t hPool = umfPoolByPtr(pMem);
if (!hPool) {
return UR_RESULT_SUCCESS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a success, probably UR_RESULT_ERROR_INVALID_MEM_OBJECT would be appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at umfFree implementation, used by urUSMFree:

umf_result_t umfFree(void *ptr) {
    umf_memory_pool_handle_t hPool = umfPoolByPtr(ptr);
    if (hPool) {
        LOG_DEBUG("calling umfPoolFree(pool=%p, ptr=%p) ...", (void *)hPool,
                  ptr);
        return umfPoolFree(hPool, ptr);
    }
    return UMF_RESULT_SUCCESS;
}

Here, if hPool is null, success is returned

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our case, user could provide invalid pointer and we would return success. Considering current umf use-cases in L0 and L0 v2 I don't think it is possible to have a valid pointer that doesn't come from umf pool.

@staniewzki staniewzki changed the title [UR][L0 v2][draft] Port USM alloc to adapter v2 [UR][L0 v2] Port USM alloc to adapter v2 Apr 30, 2025
@staniewzki staniewzki marked this pull request as ready for review April 30, 2025 11:08
@staniewzki staniewzki requested a review from a team as a code owner April 30, 2025 11:08

ur_result_t ur_context_handle_t_::retain() {
RefCount.increment();
return UR_RESULT_SUCCESS;
}

ur_result_t ur_context_handle_t_::release() {
asyncPool.cleanupPools();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be after decrementAndTest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants